package com.thyme.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.thyme.system.dao.Iec61850IedDao;
import com.thyme.system.dao.Iec61850LdDao;
import com.thyme.system.service.Iec61850LdService;
import com.thyme.system.vo.Iec61850IedVo;
import com.thyme.system.vo.Iec61850LdVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author nana
 * @since 2021-03-24
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class Iec61850LdServiceImpl  implements Iec61850LdService {
    private final Iec61850LdDao iec61850LdDao;
    @Override
    public int updateLD(Iec61850LdVo iec61850LdVo) {
        QueryWrapper<Iec61850LdVo> queryWrapper = new QueryWrapper<Iec61850LdVo>();
        queryWrapper.eq("ld_inst_name",iec61850LdVo.getLdInstName());
        queryWrapper.eq("iec61850_ied_id",iec61850LdVo.getIec61850IedId());
        Iec61850LdVo tmp =  iec61850LdDao.selectOne(queryWrapper);
        if(tmp==null){
            iec61850LdDao.insertBy(iec61850LdVo);
        }else {
            iec61850LdDao.update(iec61850LdVo,queryWrapper);
            iec61850LdVo.setId(tmp.getId());
        }
        return iec61850LdVo.getId();
    }
}
